package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.common.result.R;
import com.atguigu.srb.core.entity.UserLoginRecord;
import com.atguigu.srb.core.service.UserLoginRecordService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户登录记录表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-06-30
 */
@RestController
@RequestMapping("/admin/core/userLoginRecord")
// @CrossOrigin
@Api(tags = "会员管理登录日志查询")
public class AdminUserLoginRecordController {
    @Resource
    UserLoginRecordService userLoginRecordService;
    @ApiOperation("登录日志查询功能")
    @GetMapping("/top10/{userId}")
    public R getLogRecord(@PathVariable("userId")Long userId){
        List<UserLoginRecord> list = userLoginRecordService.list(Wrappers.lambdaQuery(UserLoginRecord.class)
                .eq(UserLoginRecord::getUserId,userId)
                .orderByDesc(UserLoginRecord::getCreateTime)
                .last("limit 10"));
        return R.ok().data("items",list);
    }
}

